package com.team.appinfo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team.appinfo.entity.AppInfo;
import com.team.appinfo.mapper.AppInfoMapper;
import com.team.appinfo.mapper.AppVersionMapper;
import com.team.appinfo.service.AppInfoService;
import com.team.appinfo.util.AppinfoDicontion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AppInfoServiceImpl implements AppInfoService {
    @Autowired
    private AppInfoMapper appInfoMapper;
    @Autowired
    private AppVersionMapper appVersionMapper;
    public PageInfo<AppInfo> searchAppInfo(AppinfoDicontion appinfoDicontion) {
        PageHelper.startPage(appinfoDicontion.getPage(),appinfoDicontion.getPageSize());
        List<AppInfo> list = appInfoMapper.getPageAppinfo(appinfoDicontion);
        return new PageInfo<AppInfo>(list);
    }

    //新增
    public int addAppInfo(AppInfo appInfo) {
        return appInfoMapper.insertSelective(appInfo);
    }

    //修改前准备根据id查询
    public AppInfo getAppInfoById(Long id) {
        return appInfoMapper.getAppinfo(id);
    }

    //更新保存
    public int updateAppInfo(AppInfo appInfo) {
        return  appInfoMapper.updateByPrimaryKeySelective(appInfo);
    }

    //删除
    @Transactional
    public void delAppInfo(Long id) {
         appInfoMapper.deleteByPrimaryKey(id);
         appVersionMapper.deleteByAppId(id);
    }

    //运营分面查询
    public PageInfo<AppInfo> getNoPassAppInfo(AppinfoDicontion appinfoDicontion) {
        PageHelper.startPage(appinfoDicontion.getPage(),appinfoDicontion.getPageSize());
        List<AppInfo> list = appInfoMapper.getNoPassAppinfo(appinfoDicontion);
        return new PageInfo<AppInfo>(list);
    }

    // //根据appId查询当前数据
    public AppInfo getModernAppInfo(Long id) {
        return appInfoMapper.getModernAppInfo(id);
    }


    //审核状态
    public int approvalStatus(Long id, Long status) {
        AppInfo appInfo = new AppInfo();
        appInfo.setId(id);
        appInfo.setStatus(status);
        return this.appInfoMapper.updateByPrimaryKeySelective(appInfo);
    }

    public int updateAppInfoState(Long appId, Long status) {
        return 0;
    }
}
